import pygame
from random import randint

numLayers = 5
starsPerLayer = 20
class BG:
    def __init__(self):
        self.stars = []
        dimmer = 1
        for layer in range(numLayers):
            self.stars.append([])
            for star in range(starsPerLayer):
                brightness = int(randint(150, 255) / dimmer)
                # a position and a color
                self.stars[-1].append((randint(0, 640), \
                                        randint(0, 640), \
                        (randint(brightness * 3 / 4, brightness), \
                         randint(brightness * 3 / 4, brightness), \
                         randint(brightness * 3 / 4, brightness))))
            dimmer += .3

    def draw(self, surface, thisShip):
        """updates the HUD and draws it."""
        depth = 1.
        for layer in self.stars:
            for star in layer:
                pygame.draw.rect(surface, star[2], \
                    ((star[0] - thisShip.x / depth) % 640,
                    (star[1] - thisShip.y / depth) % 640, 2, 2))
            depth = depth * 3 / 2